package com.yu.rabbitmq.six;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.yu.rabbitmq.utils.RabbitMqUnits;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class DirectLogs {

    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitMqUnits.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);//声明交换机
        //生成一个临时队列
        String queue = channel.queueDeclare().getQueue();
        //绑定交换机和队列
        channel.queueBind(queue,EXCHANGE_NAME,"error");
        System.out.println("等待接收消息。。。");

        DeliverCallback deliverCallback = (consumerTag, message)->{
            System.out.println("ReceiveLogs01接收的消息是:"+new String(message.getBody(), "UTF-8"));
        };

        channel.basicConsume(queue,true,deliverCallback,consumerTag -> {});
    }
}
